package com.bjgzy.courselive.mvp.ui.adapter;

import android.widget.ImageView;
import android.widget.TextView;

import com.bjgzy.module_couselive.R;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.eduhzy.ttw.commonsdk.entity.MyCourseData;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;

import java.util.List;

/**
 * @author xubo
 * @date 2018/8/1 15:02
 */
public class MyCourseMultiAdapter extends BaseMultiItemQuickAdapter<MyCourseData, AutoBaseViewHolder> {
    public static final int ITEM = 1;
    /**
     * 猜你喜欢label
     */
    public static final int LABEL = 2;
    /**
     * 猜你喜欢
     */
    public static final int ITEM_AD = 3;

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public MyCourseMultiAdapter(List<MyCourseData> data) {
        super(data);
        this.addItemType(ITEM, R.layout.courselive_rv_item_mycourse);
        this.addItemType(LABEL, R.layout.courselive_rv_item_mycourse_label);
        this.addItemType(ITEM_AD, R.layout.courselive_rv_item_mycourse_ad);
    }

    @Override
    protected void convert(AutoBaseViewHolder helper, MyCourseData item) {
        switch (item.getItemType()) {
            case ITEM:
                TextView tv = helper.getView(R.id.tv_time);
                tv.setText(item.getPlayInfo());
                switch (item.getColor()) {
                    case 0:
                        helper.setGone(R.id.btn_new, false);
                        tv.setSelected(false);
                        break;
                    case 1:
                        helper.setGone(R.id.btn_new, true);
                        tv.setSelected(true);
                        break;
                    default:
                }
                Glide.with(mContext)
                        .load(item.getPreImage())
                        .apply(RequestOptions.placeholderOf(R.drawable.public_img_default).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL))
                        .into((ImageView) helper.getView(R.id.iv_avatar));
                helper.setText(R.id.tv_title, item.getTitle());
                helper.setText(R.id.tv_shop, item.getShopName());
                break;
            case LABEL:

                break;
            case ITEM_AD:

                break;
            default:

                break;
        }
    }
}
